package ch.fhnw.qualiscan.application.modals;

import java.util.List;

import ch.fhnw.qualiscan.application.models.SurveyModel;
import ch.fhnw.qualiscan.core.Modal;
import ch.fhnw.qualiscan.core.db.helpers.participantsTableArgs;
import ch.fhnw.qualiscan.core.db.pojos.SurveyUserRole;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.Table;

import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class ShowParticipants extends Modal {
	
	private Table participantsTable;
	private BeanItemContainer<participantsTableArgs> tableContainer;
	
	private SurveyUserRole sur;
	
	public ShowParticipants(SurveyUserRole sur) {
		
		this.sur = sur;
		
		setCaption(TM.get("evaluation.seeparticipants"));

		tableContainer = new BeanItemContainer<participantsTableArgs>(participantsTableArgs.class);
		
		SurveyModel sM = new SurveyModel();
		List<SurveyUserRole> surList = sM.getSurListForSurvey(sur.getSurvey());
		
		for(SurveyUserRole surEntry : surList) {
			participantsTableArgs pta = new participantsTableArgs(this.sur,
					surEntry.getUser().getFirstname(), 
					surEntry.getUser().getLastname(),
					surEntry.getUser().getEmail(), 
					"none");
			tableContainer.addBean(pta);
		}
		
		participantsTable = new Table();
		participantsTable.setWidth("100%");
		participantsTable.setPageLength(10);
		participantsTable.setSelectable(false);
		participantsTable.setContainerDataSource(tableContainer);
		
		participantsTable.setColumnHeader("firstname", TM.get("editsurvey.participantstable.firstname"));
		participantsTable.setColumnHeader("lastname", TM.get("editsurvey.participantstable.lastname"));
		participantsTable.setColumnHeader("email", TM.get("editsurvey.participantstable.email"));
		
		participantsTable.setVisibleColumns(new Object[]{"firstname", "lastname", "email"});
		
		addComponent(participantsTable);
	}

}
